/*!
 * @file gfxPosteffects.cpp
 * @brief Ciało gfxPosteffects.hh
 */

#include "engine/gfx/gfxPosteffects.hh"
using namespace std;

/*--------------------------------------------------------------------------*/

gfxPosteffects::gfxPosteffects() {

	/*
	 * Inicjalizacja blooma
	 */
	this->bloomActive = &pawirr::set->put("pfx_bloom", 1)->i;
	this->bloomShader = new shader("bloomShader");
	this->bloomShader->addShader("pawirr/shaders/bloom.v", ST_V);
	this->bloomShader->addShader("pawirr/shaders/bloom.f", ST_F);
	this->bloomShader->linkProgram();

	pawirr::graphic->_env->addEnvUniforms(this->bloomShader);

	this->bloomShader->addTexture("tex_screen", this->tempTexture);

	/*
	 * tekstura "tymczasowa"
	 */
	this->tempTexture = new texture(pawirr::graphic->resX,
			pawirr::graphic->resY);

}

/*--------------------------------------------------------------------------*/

void gfxPosteffects::paintAll() {

	if (*this->bloomActive) {
		this->bloomFunc();
	}

}

/*--------------------------------------------------------------------------*/
void gfxPosteffects::bloomFunc() {

	/*
	 * Kopiowanie ekranu do tekstury
	 */
	this->tempTexture->copyColorBuffer();

	/*
	 * Włączanie shadera
	 */
	this->bloomShader->bind();

	/*
	 * Malowanie tekstury na ekranie
	 */
	pawirr::graphic->_pri->putRectangle(point2f(0.0f, 0.0f), point2f(
			this->tempTexture->w, this->tempTexture->h), color_white,
			this->tempTexture);

	/*
	 * Wyłączanie shadera
	 */
	this->bloomShader->unbind();
}

/*--------------------------------------------------------------------------*/
